package com.org.khtn.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.util.EventObject;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.event.CellEditorListener;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

public class RowHeaderRenderer extends JLabel implements TableCellRenderer {
	public Vector primaryKeys;

	public RowHeaderRenderer(Vector keys) {
		super();
		setOpaque(true);
		primaryKeys = keys;
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		if (isSelected) {
			setBackground(Color.lightGray);
			
		} else {
			setBackground(new Color(240,240,240));
		}
		if (hasRow(primaryKeys,row)) {
			setIcon(new ImageIcon("res/images/key.gif"));
		} else {
			setIcon(null);
		}
		return this;
	}
	
	public void setPrimaryKey(Vector keys) {
		//primaryKey = n;
		primaryKeys = keys;
	}
	
	public void removePrimaryKey() {
		primaryKeys.removeAllElements();
	}
	
	public boolean hasRow(Vector keys, int row) {
		if (keys.size() == 0)
			return false;
		for (int i=0; i<keys.size(); i++)  {
			int n = (int)keys.elementAt(i);
			if (n == row) {
				return true;
			}
		}
		return false;
	}
}
